#coding:utf-8
from commands import getstatusoutput as shell
def get_tag_from_file(url):
	f = open(url,'r')
	res = f.readlines()
	f.close()
	_list = []
	for items in res:
		if items.find('s.version') != -1:
			_list.append(items)
	verStr = _list[0]
	c = verStr.strip()
	index = c.find('\'')
	tag = c[index+1:-1]
	return tag

def get_podspec_file():
	res = shell('ls |grep *.podspec')
	return res[1]

def copy_podspect_to_repo(podspec_file, tag):
	shell('''mkdir -p ../CYSpec/CYTool/%s'''%tag)
	shell('''cp -rf %s ../CYSpec/CYTool/%s/'''%(podspec_file,tag))

def commit_coding(tag):
	shell('git add *')
	shell('''git commit -m "auto commit"''')
	shell('''git tag -a %s -m "auto tag"'''%tag)
	shell('git push')
	shell('git push origin --tags')
	shell('''cd ../CYSpec;git add *;git commit -m "auto commit";git push''')
	shell('pod repo update CYRepo')


podspec_file = get_podspec_file()
print podspec_file
tag = get_tag_from_file(podspec_file)
print tag
copy_podspect_to_repo(podspec_file, tag)
commit_coding(tag)

